<?php include('_init_.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>班尼頓寫真後台管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="../css/admin-body.css" rel="stylesheet" type="text/css" />
<link href="../css/ConAdd.css" rel="stylesheet" type="text/css" />
<link href="../css/uploadifyb.css" rel="stylesheet" type="text/css" />
<link href="../css/jquery/smoothness/jquery-ui-1.10.2.custom.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.10.2.datepicker.min.js"></script>
<script type="text/javascript" src="../js/swfobject.js"></script>
<script type="text/javascript" src="../js/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
var global_sub_cat_table = {};
var global_uploaded_a_image = [];
<?php 
foreach($GLOBALS['GV_ARTICLE_SUB_CAT'] as $cat_id=>$sub_cat_list)
{
	printf("global_sub_cat_table[%d]={};",$cat_id);
	foreach($sub_cat_list as $sub_cat_id=>$sub_cat_name)
	{
		printf("global_sub_cat_table[%d][%d] = '%s';",$cat_id,$sub_cat_id,$sub_cat_name);
	}
}	
?>
</script>
<script type="text/javascript">
// <![CDATA[
$(function(){
	$(".uploadifyupload").each(function(){
		
		var previous_img_id = $(this).attr('name');
		$(this).uploadify({
			'uploader': 'uploadify.swf',
			'cancelImg': 'cancel.png',
			'script': 'uploadify.php',
			'folder': 'files',
			'multi': false,
			'fileExt':'*.jpg;*.jpeg;*.gif;*.png',
				'fileDesc':'Image Files',
			'auto': true,
			'scriptData':{'<?php echo session_name();?>':'<?php echo session_id();?>','name':$(this).attr('name'),'responsetype':'sizeinfo'},
			'displayData': 'speed',
			'onComplete':function(event,queueID,fileObj,response,data){
				var responseObj = eval("("+response+")");
				var fileName = responseObj.name;
				$('#img_'+previous_img_id).attr('src','../img/tmp/' + fileName);
				$('#img_'+previous_img_id).show();
				$('input[name=ajaxf_'+previous_img_id+']').val(fileName);
				
			},
			'onError':function(event,queueId,fileObj,errorObj){
				alert(errorObj);
			}
		});
	});
});

$(function(){
	$('.datepicker').datepicker({ dateFormat: "yy-mm-dd" });
	$('.ck_cat_id').click(function(){
		   $('.ck_cat_id').attr('checked',false);
		   $(this).attr('checked',true);
		   //toggle display style
		   var cat_id_val = $('.ck_cat_id:checked').val();

		   $('.display_style_span').hide();
		   if ( cat_id_val == 1){
			   $('.display_style_span_1').show();
			   $('.display_style_span_2').show();
		   }
		   else if ( cat_id_val == 2){
			   $('.display_style_span').show();
		   }
		   else if ( cat_id_val == 3){
			   $('.display_style_span_2').show();
			   $('.ck_display_style_id').attr('checked',false);
			   $('.display_style_span_2 input').attr('checked',true);
				 //toggle A display style images upload panel
			   var display_style = $('.ck_display_style_id:checked').val();
			   if ( display_style == 1 ) {
			  		 $('#ul_a_image_panel').show();
			   }else{
				   $('#ul_a_image_panel').hide();
			   }
		   }
		   
		   refresh_sub_cat();
			 //toggle upload image2
		   var cat_id_val = $('.ck_cat_id:checked').val();
		   var sub_cat_id_val = $('.ck_sub_cat_id:checked').val();
		   if ( cat_id_val == 2 &&  sub_cat_id_val == 5) {
		  		 $('#ul_c_image_panel').show();
		  		
		   }else{
			   $('#ul_c_image_panel').hide();
			  
		   }
		});
	$('.ck_display_style_id').click(function(){
		   $('.ck_display_style_id').attr('checked',false);
		   $(this).attr('checked',true);

			//toggle A display style images upload panel
		   var display_style = $('.ck_display_style_id:checked').val();
		   if ( display_style == 1 ) {
		  		 $('#ul_a_image_panel').show();
		   }else{
			   $('#ul_a_image_panel').hide();
		   }
		   
		   
		});

	refresh_sub_cat();
	//toggle A display style images upload panel
	   var display_style = $('.ck_display_style_id:checked').val();
	   if ( display_style == 1 ) {
	  		 $('#ul_a_image_panel').show();
	   }else{
		   $('#ul_a_image_panel').hide();
	   }

	   //toggle display style
	   var cat_id_val = $('.ck_cat_id:checked').val();
	   $('.display_style_span').hide();
	   if ( cat_id_val == 1){
		   $('.display_style_span_1').show();
		   $('.display_style_span_2').show();
	   }
	   else if ( cat_id_val == 2){
		   $('.display_style_span').show();
	   }
	   else if ( cat_id_val == 3){
		   $('.display_style_span_2').show();
	   }
		 
	$('#li_sub_cat input[value=<?php echo $GLOBALS['PAGE_FORM_DATA']['sub_cat_id']?>]').attr('checked',true);
});
function refresh_sub_cat()
{
	$('#li_sub_cat').text("選擇文章類別:    ");
	var cat_id = $('.ck_cat_id:checked').val();
	if ( cat_id && global_sub_cat_table[cat_id]) {
		for(var sub_cat_id in global_sub_cat_table[cat_id]){
			$('#li_sub_cat').append("<input type='checkbox' name='sub_cat_id' value='"+sub_cat_id+"' class='ck_sub_cat_id'/>&nbsp;"+global_sub_cat_table[cat_id][sub_cat_id] + '&nbsp;&nbsp;&nbsp;&nbsp;');
		}
		$('#li_sub_cat').parent().show();
	}else{
		$('#li_sub_cat').parent().hide();
	}

	$('.ck_sub_cat_id').click(function(){
		   $('.ck_sub_cat_id').attr('checked',false);
		   $(this).attr('checked',true);

		   //toggle upload image2
		   var cat_id_val = $('.ck_cat_id:checked').val();
		   var sub_cat_id_val = $('.ck_sub_cat_id:checked').val();
		   if ( cat_id_val == 2 &&  sub_cat_id_val == 5) {
		  		 $('#ul_c_image_panel').show();
		  		
		   }else{
			   $('#ul_c_image_panel').hide();
			  
		   }
		});
}


// ]]>
</script>
<script language="javascript" src="../js/rAlertb.js"></script>
<script language="javascript">
function edit_toa(id) {
	 global_uploaded_a_image = [];
	 $('.addcon-c .a-display-style-img-add').remove();
	 rAlert("working-photo-add.php?sid=<?php echo session_id();?>" , null, "新增相片",810, 600);
}
function working_photo_add_uploaded_image(img_url)
{
	global_uploaded_a_image.push(img_url);
	$('.addcon-c').append('<p class="photoa a-display-style-img-add"><img src="../img/tmp/'+img_url+'" width="200" height="300" /><a href="#del">&nbsp;</a></p>');
}
function working_photo_add_uploaded_image_complete()
{
	rClose();
}
function check_and_post_form()
{
	if ( $('.ck_cat_id:checked').length == 0 ) {
		alert('請選擇類别');
		window.scrollTo(0,0);
		return false;
	}
	if ( $('.ck_display_style_id:checked').length == 0 ) {
		alert('請選擇文章格式');
		window.scrollTo(0,0);
		return false;
	}
	var cat_id = $('.ck_cat_id:checked').val();
	if ( cat_id && global_sub_cat_table[cat_id]) {
		if ( $('.ck_sub_cat_id:checked').length == 0 ) {
			alert('請選擇文章類別');
			window.scrollTo(0,0);
			return false;
		}
	}
	var form = document.forms['page_form'];
	if ( form.date.value == '' ) {
		alert('請選擇日期');
		window.scrollTo(0,0);
		return false;
	}
	if ( form.title.value == '' ) {
		alert('請錄入文章標題');
		window.scrollTo(0,0);
		return false;
	}
	form.a_style_img.value = global_uploaded_a_image.join(',');
	form.submit();
	return false;
}
</script>
<script src="<?php echo constant('APP_JS_LIB_DIR');?>/ckeditor/ckeditor.js"></script>
</head>

<body>
<?php include_once('admin-top.php');?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>" name="page_form"> 
<input type="hidden" name="id" value="<?php echo $GLOBALS['PAGE_FORM_DATA']['id'];?>"/>
<input type="hidden" name="act" value="save"/>
<input type="hidden" name="a_style_img" value=""/>
<div id="main" class="clearfix"><!-- star #main //-->
  
  <div id="contactall"><!-- star #main //-->
  <div id="tit" ><!-- star #tit //-->
    <ul>
    <li class="tit-a"><?php echo  $GLOBALS['PAGE_FORM_DATA']['id'] > 0 ?'修改':'新增'; ?><?php if ( array_key_exists( $GLOBALS['PAGE_FORM_DATA']['cat_id'], $GLOBALS['GV_ARTICLE_CAT'] ) ) { echo $GLOBALS['GV_ARTICLE_CAT'][$GLOBALS['PAGE_FORM_DATA']['cat_id']];} else {echo '文章';}?></li>
    </ul>
  </div><!-- end #tit //-->
  <div id="contact" class="clearfix" ><!-- star #contact //-->
    <ul>
      <li>選擇類別： 
      <?php foreach($GLOBALS['GV_ARTICLE_CAT'] as $id=>$name):?>
       <input type="checkbox" <?php if ($GLOBALS['PAGE_FORM_DATA']['cat_id'] == $id):?>checked="checked"<?php endif;?>  name="cat_id" value="<?php echo $id;?>" class="ck_cat_id"/>&nbsp;<?php echo $name;?>
       &nbsp;&nbsp;
      <?php endforeach;?>
    </li>
    </ul>
    <ul>
      <li>文章格式： 
      <?php foreach($GLOBALS['GV_ARTICLE_DISPLAY_STYLE'] as $id=>$name):?>
      <span class="display_style_span display_style_span_<?php echo $id?>" style="margin-right:10px;">
       <input type="checkbox"  <?php if ($GLOBALS['PAGE_FORM_DATA']['display_style_id'] == $id):?>checked="checked"<?php endif;?> name="display_style_id" value="<?php echo $id;?>" class="ck_display_style_id"/>&nbsp;<?php echo $name;?>
       </span>
      <?php endforeach;?>
    </li>
    </ul>
    <ul style="display:none;">
      <li id="li_sub_cat"></li>
    </ul>
    <ul>
      <li>文章標題： <input name="title" type="text" class="keyina" placeholder="請輸入文章的標題" value="<?php echo $GLOBALS['PAGE_FORM_DATA']['title'];?>"/>
    </li>
    </ul>
    <ul>
      <li>日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期： <input name="date" type="text" class="keyina datepicker" placeholder="請選擇日期" value="<?php echo $GLOBALS['PAGE_FORM_DATA']['date'];?>"/>
    </li>
    </ul>
    <ul>
      <li>上傳文章列表圖片：</li>
    <li class="addcon-a">
        <input class="uploadifyupload" type="file" name="image" id="imageswfupload"/> 
        <input name="ajaxf_image" type="hidden"/>
        </li>
    <li>
    <?php if ($GLOBALS['PAGE_FORM_DATA']['img_path']):?>
    <img  id="img_image" width="430" height="287" src="../img/article/<?php echo $GLOBALS['PAGE_FORM_DATA']['img_path'];?>"/>
    <?php else:?>
     <img src="#" id="img_image" width="430" height="287" style="display:none"/>
    <?php endif;?>
    </li>
    </ul>
    
    <ul id="ul_a_image_panel">
      <li class="addcon-b">上傳A格式圖片：<a href="#" onclick="javascript:edit_toa(1118);return false;">上傳</a></li>
    <li class="addcon-c">
    <?php foreach($GLOBALS['PAGE_FORM_DATA']['a_style_img'] as $row):?>
    <p class="photoa"><img src="../img/article/<?php echo $row['path'];?>" width="200" height="300" /><a href="contact-add.php?act=delete_a_style_img&sub_cat_id=<?php echo $_REQUEST['sub_cat_id']?>&id=<?php echo $row['id'];?>" onclick="return confirm('確定刪除');">刪除</a></p>
    <?php endforeach;?>
    </li>
    </ul>
    
    <ul id="ul_c_image_panel">
    <li>上傳優惠卷：</li>
    <li class="addcon-a">
     <input class="uploadifyupload" type="file" name="image2" id="image2swfupload"/> 
     <input name="ajaxf_image2"" type="hidden"/>
    </li>
    <li>
     <?php if ($GLOBALS['PAGE_FORM_DATA']['img2_path']):?>
    <img id="img_image2" width="710" height="473" src="../img/article/<?php echo $GLOBALS['PAGE_FORM_DATA']['img2_path'];?>"/>
     <?php else:?>
     <img src="" id="img_image2" width="710" height="473" style="display:none"/>
      <?php endif;?>
    </li>
    </ul>
    
  </div><!-- end #contact //-->
  <div id="ContactHtm" ><!-- star #contactHtm //-->
    <textarea class="ckeditor" name="content"><?php echo $GLOBALS['PAGE_FORM_DATA']['content'];?></textarea>
   </div><!-- end #contactHtm //-->
    <div id="ContactSet" class="clearfix" ><!-- star #contactSet //-->
    <ul>
    <li class="cs-1">關鍵字管理（可以選擇五組關鍵字）</li>
    <li class="cs-2">
    <?php foreach($GLOBALS['META_KEY_WORDS']  as $id=>$name):?>
    <p><input  type="checkbox" <?php if(in_array($id, $GLOBALS['PAGE_FORM_DATA']['meta_keyword'])):?>checked="checked"<?php endif;?> value="<?php echo $id;?>" class="checkbox" name="meta_keyword[]"/>&nbsp;&nbsp;<?php echo $name;?></p>
    <?php endforeach;?>
    </li>
    <li class="cs-1">描述內容（最多70個中文字元或是140個英文字元）</li>
    <li class="cs-3">
      <textarea name="meta_description" class="cs-3a"><?php echo $GLOBALS['PAGE_FORM_DATA']['meta_description'];?></textarea>
    </li>
    <li class="cs-4"><a href="#" onclick="return check_and_post_form();">儲存</a> </li>
    </ul>
    </div><!-- end #contactSet //-->
  </div><!-- end #contactall //-->
</div><!-- end #main //-->
</form>
</body>
</html>